package cn.rdq.iknesssystem.service.impl;

import cn.rdq.api.po.Admin;
import cn.rdq.api.vo.LoginUser;
import cn.rdq.common.util.Md5Util;
import cn.rdq.dao.AdminMapper;
import cn.rdq.iknesssystem.service.AdminService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    @Override
    public Admin login(LoginUser loginUser) {
        QueryWrapper<Admin> wrapper = new QueryWrapper<>();
        wrapper.select("id", "username", "email", "avatar")
                .eq("username", loginUser.getUsername())
                .eq("password", Md5Util.encodeByMD5(loginUser.getPassword()));
        return getOne(wrapper);
    }

    @Override
    public Admin getAdminInfoById(Long id) {
        QueryWrapper<Admin> wrapper = new QueryWrapper<>();
        wrapper.select("id", "username", "email", "avatar")
                .eq("id", id);
        return getOne(wrapper);
    }
}
